package com.yale.elasticsearch.controller.base;

import com.yale.elasticsearch.dto.IndexNameDTO;
import com.yale.elasticsearch.service.base.IndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author :yale
 * @date : 2024/8/1
 */
@Api(tags = "基础操作-索引操作")
@RestController
@RequestMapping("/index")
public class IndexController {

    @Resource
    private IndexService indexService;

    @ApiOperation(value = "验证索引是否存在", notes = "验证索引是否存在")
    @GetMapping("/exist/{name}")
    public Object existIndex(@ApiParam(value = "索引名称", required = true) @PathVariable(value = "name") String indexName) {
        return indexService.existsIndex(indexName);
    }

    @ApiOperation(value = "新增索引", notes = "新增加索引信息")
    @PostMapping
    public Object createIndex(@RequestBody IndexNameDTO indexNameDTO) {
        return indexService.createIndex(indexNameDTO);
    }

    @ApiOperation(value = "删除索引", notes = "删除索引信息")
    @DeleteMapping("/{name}")
    public Object deleteIndex(@ApiParam(value = "索引名称", required = true) @PathVariable(value = "name") String indexName) {
        return indexService.deleteIndex(indexName);
    }

}